<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .container {
        width: 375px;
        height: 667px;
        border: 1px solid #000;
        position: relative;
      }
      header {
        width: 100%;
        height: 70px;
        border-bottom: 1px solid #000;
        text-align: center;
        line-height: 70px;
      }
      footer {
        position: absolute;
        width: 100%;
        height: 80px;
        left: 0;
        bottom: 0;
        border-top: 1px solid #000;
        display: flex;
        justify-content: space-evenly;
        align-items: center;
      }
      .item {
        width: 335px;
        height: 130px;
        margin: 20px;
        border: 1px solid #000;
      }
    </style>
  </head>
  <body>
    <!-- 每一个组件都必须只有一个根元素，并且不能是template -->
    <div id="app">
      <blog></blog>
    </div>

    <script src="../Vue.js"></script>
    <script>
      const BlogButton = {
        props: ["text"],
        data() {
          return {
            size: 20,
          };
        },
        template: `
          <button @click="handleClick">{{ text }}</button>
        `,
        methods: {
          handleClick() {
            this.size++;
            this.$emit("gs", this.size);
          },
        },
      };

      // 博客的头部组件
      const BlogHeader = {
        template: `
          <header>博客首页</header>
        `,
      };

      // 列表项组件
      const BlogListItem = {
        props: ["item"],
        data() {
          return {
            size: 20,
          };
        },
        template: `
          <div class="item" :style="{fontSize: size + 'px'}">
            <h3>{{ item.title }}</h3>
            <p>{{ item.content }}</p>
            <blog-button text="👍" @gs="getsize"></blog-button>
          </div>
        `,
        components: {
          BlogButton,
        },
        methods: {
          getsize(size) {
            this.size = size;
          },
        },
      };

      // 博客的list组件
      const BlogList = {
        props: ["list"],
        template: `
          <main>
            <blog-list-item
              v-for="item in list"
              :key="item.id"
              :item="item"
            ></blog-list-item>
          </main>
        `,
        components: {
          BlogListItem,
        },
      };

      // 博客的底部组件
      const BlogFooter = {
        template: `
          <footer>
            <textarea></textarea>
            <blog-button text="发布"></blog-button>
          </footer>
        `,
        components: {
          BlogButton,
        },
      };

      // 全局的最大的博客组件
      const Blog = {
        data() {
          return {
            list: [
              {
                title: "总书记和代表委员的故事",
                content: "“我要给他看看玉麦的新变化”",
                id: 1,
              },
              {
                title: "习近平对这个群体格外关心",
                content: "北京冬残奥会开幕在即",
                id: 2,
              },
              {
                title: "这里是春天的中国！",
                content: "这里是春天的中国！",
                id: 3,
              },
            ],
          };
        },
        template: `
          <div class="container">
            <blog-header></blog-header>
            <blog-list :list="list"></blog-list>
            <blog-footer></blog-footer>
          </div>
        `,
        components: {
          BlogHeader,
          BlogList,
          BlogFooter,
        },
      };

      new Vue({
        el: "#app",
        data: {},
        // 组件注册
        components: {
          Blog,
        },
      });
    </script>
  </body>
</html>
